package com.guoxiang.bigdata.httptest;


import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import java.io.IOException;

public class HttpClientOps {

    public static void main(String[]args) throws IOException {
        //创建http客户端对象
        HttpClient httpClient= HttpClients.createDefault();
        HttpGet httpGet=new HttpGet("https://tieba.baidu.com/f?kw=%E7%BE%8E%E5%A5%B3&ie=utf-8&pn=50");
        httpGet.setHeader("User-Agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36");
        HttpHost httpHost = new HttpHost("125.123.140.46",9999);
        RequestConfig requestConf = RequestConfig.custom().setProxy(httpHost).build();
        httpGet.setConfig(requestConf);
        //点击 返回响应实体
        HttpResponse httpResponse=httpClient.execute(httpGet);
        //从响应数据包中获取响应实体
        HttpEntity entity =httpResponse.getEntity();
        String ret = EntityUtils.toString(entity);
        System.out.println(ret);
    }









}
